package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import java.util.Objects;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.vo.req.BatchTaskReqVO;
import com.ruoyi.system.vo.req.TaskCheckDetailReqVO;
import com.ruoyi.system.vo.resp.TaskReqDTO;
import com.ruoyi.system.vo.resp.TaskRespDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.FkwzTask;
import com.ruoyi.system.service.IFkwzTaskService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 任务检查Controller
 * 
 * @author ruoyi
 * @date 2024-06-04
 */
@RestController
@RequestMapping("/task")
public class FkwzTaskController extends BaseController
{
    @Autowired
    private IFkwzTaskService fkwzTaskService;

    /**
     * 查询任务检查列表
     */
    @RequiresPermissions("system:task:list")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody TaskReqDTO fkwzTask)
    {
        startPage();
        List<TaskRespDTO> list = fkwzTaskService.selectFkwzTaskList(fkwzTask);
        return getDataTable(list);
    }

    /**
     * 导出任务检查列表
     */
    @RequiresPermissions("system:task:export")
    @Log(title = "任务检查", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TaskReqDTO fkwzTask)
    {
        List<TaskRespDTO> list = fkwzTaskService.selectFkwzTaskList(fkwzTask);
        ExcelUtil<TaskRespDTO> util = new ExcelUtil<TaskRespDTO>(TaskRespDTO.class);
        util.exportExcel(response, list, "任务检查数据");
    }

    /**
     * 获取任务检查详细信息
     */
    @RequiresPermissions("system:task:getInfo")
    @GetMapping(value = "/{taskId}")
    public AjaxResult getInfo(@PathVariable("taskId") Long taskId)
    {
        return AjaxResult.success(fkwzTaskService.selectFkwzTaskByTaskId(taskId));
    }

    /**
     * 新增任务
     */
    @RequiresPermissions("system:task:add")
    @Log(title = "任务检查", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FkwzTask fkwzTask)
    {
        return toAjax(fkwzTaskService.insertFkwzTask(fkwzTask));
    }

    /**
     * 批量新增任务检查
     */
    @RequiresPermissions("system:task:addbatch")
    @Log(title = "批量新增任务检查", businessType = BusinessType.INSERT)
    @PostMapping("/addBatch")
    public AjaxResult addBatch(@RequestBody @Validated BatchTaskReqVO vo)
    {
        return toAjax(fkwzTaskService.insertBatchFkwzTask(vo));
    }


    /**
     * 修改任务检查
     */
    @RequiresPermissions("system:task:edit")
    @Log(title = "任务检查", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody FkwzTask fkwzTask)
    {
        return toAjax(fkwzTaskService.updateFkwzTask(fkwzTask));
    }

    /**
     * 删除任务检查
     */
    @RequiresPermissions("system:task:remove")
    @Log(title = "任务检查", businessType = BusinessType.DELETE)
	@PostMapping("/{taskIds}")
    public AjaxResult remove(@PathVariable Long[] taskIds)
    {
        return toAjax(fkwzTaskService.deleteFkwzTaskByTaskIds(taskIds));
    }


    /**
     * 新增任务检查详情
     */
    @RequiresPermissions("system:task:addOrUpdateTaskDetail")
    @Log(title = "任务检查", businessType = BusinessType.INSERT)
    @PostMapping("/addOrUpdateTaskDetail")
    public AjaxResult addOrUpdateTaskDetail(@RequestBody @Validated TaskCheckDetailReqVO reqVO)
    {
        fkwzTaskService.addOrUpdateTaskDetail(reqVO);
        return AjaxResult.success();
    }



    /**
     * 查询任务检查列表
     */
//    @RequiresPermissions("system:task:checkRecordList")
    @PostMapping("/checkRecordList")
    public TableDataInfo checkRecordList(@RequestBody TaskReqDTO fkwzTask)
    {
        startPage();
        List<TaskRespDTO> list = fkwzTaskService.checkRecordList(fkwzTask);
        return getDataTable(list);
    }

    /**
     * 检查记录统计
     */
//    @RequiresPermissions("system:task:checkRecordList")
    @PostMapping("/checkRecordCount")
    public R checkRecordCount(@RequestBody TaskReqDTO fkwzTask)
    {
       Object obj = fkwzTaskService.checkRecordCount(fkwzTask);
        return R.ok(obj);
    }


    /**
     * 检查记录检查状态统计
     */
//    @RequiresPermissions("system:task:checkStatusCount")
    @PostMapping("/checkStatusCount")
    public R checkStatusCount(@RequestBody TaskReqDTO fkwzTask)
    {
        Object obj = fkwzTaskService.checkStatusCount(fkwzTask);
        return R.ok(obj);
    }


    /**
     * 隐患检查列表
     */
//    @RequiresPermissions("system:task:selectWarnList")
    @PostMapping("/selectWarnList")
    public TableDataInfo selectWarnList(@RequestBody TaskReqDTO fkwzTask)
    {
        startPage();
        List<TaskRespDTO> list = fkwzTaskService.selectWarnList(fkwzTask);
        return getDataTable(list);
    }





}
